{include file="public/header" /}
<body class="gray-bg">
<div class="layui-fluid layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-header">添加幻灯片</div>
        <div class="layui-card-body layui-form">
            <div class="layui-row layui-col-space10 layui-form-item ">
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">banner图片上传</label>
                    <input type="hidden" name="img" id="lay-img" lay-verify="image">
                    <div class="layui-input-block">
                        <div id="lay-upload">上传图片</div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            预览图：
                            <div class="layui-upload-list" id="lay-img-list">
                            </div>
                        </blockquote>
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="orderby" lay-verify="required|orderby" placeholder="输入排序值" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">是否首页</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_home" value="1" title="是" lay-filter="remind_type" checked>
                        <input type="radio" name="is_home" value="2" title="否" lay-filter="remind_type_no">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="remind" style="display: none;">
                    <label class="layui-form-label">banner标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" id="title" placeholder="输入banner标题" class="layui-input " autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="开启" checked>
                        <input type="radio" name="status" value="2" title="禁用" >
                    </div>
                </div>
                <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                        </button>
                        <button class="layui-btn layui-btn-primary" onclick="history.back()">关闭</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>

    // 图片上传
    if("{$configState}" == 0){
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('Upload/upload')}",domain:"{:config('DOMAIN')}"});
    }else {
        wk.uploadImg({size:2,type:'jpg,jpeg,png',url:"{:url('admin/upload/uploadLocality')}"});
    }

    layui.use(['form','element','upload'], function() {
        var form = layui.form
            , element = layui.element
            , upload = layui.upload

        form.verify({
            image:[/\S/,'请上传图片'],
            orderby:[/^(0|[1-9]\d*)$/,'排序值只能为非负整数']
        });

        form.on('radio(remind_type)', function (data) {
            document.getElementById('remind').style.display = 'none';
            $("#title").attr('lay-verify',false);
            form.render('radio');
        });

        form.on('radio(remind_type_no)', function (data) {
            document.getElementById('remind').style.display = 'block';
            $("#title").attr('lay-verify','required');
        });

        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('add_filmstrip')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            setTimeout(function () {
                                wk.layer_close();
                                window.location.href="{:url('Filmstrip/index')}";
                            },100);
                        })
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>